
/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.analysisModel;

import java.io.Serializable;

import br.ufmg.dees.insane.util.IMatrix;
import br.ufmg.dees.insane.util.IVector;

/** A class representing a PolarPlaneStress
 * @author jamile
 * 17/11/2005
 */
public class PolarPlaneStress extends PolarPlane implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	/**Constructs a Polar Plane Stress Analysis Model.*/
    public PolarPlaneStress()
	{
    	super();
	}
    
    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getInternalVariableOperator(br.ufmg.dees.insane.util.IMatrix, br.ufmg.dees.insane.util.IVector, br.ufmg.dees.insane.util.IMatrix)
     */
    public IMatrix getInternalVariableOperator(IMatrix d, IMatrix d2, IVector n, IMatrix c) {
    	int nNos = d.getNumCol();
        IMatrix dG = new IMatrix(2,d.getNumCol());
        IMatrix b = new IMatrix(6,(3*nNos));
        dG.setZero();
        b.setZero();
        IMatrix J1 = this.invertJacobian(this.getJacobian(d, c));
        dG.mul(J1,d);
        for(int i=0; i<nNos; i++) 
        {
            b.setElement(0,(3*i),dG.getElement(0,i));
            b.setElement(1,((3*i)+1),dG.getElement(0,i));
            b.setElement(1,((3*i)+2),-n.getElement(i));
            b.setElement(2,(3*i),dG.getElement(1,i));
            b.setElement(2,((3*i)+2),n.getElement(i));
            b.setElement(3,((3*i)+1),dG.getElement(1,i));
            b.setElement(4,((3*i)+2),dG.getElement(0,i));
            b.setElement(5,((3*i)+2),dG.getElement(1,i));
        }
        return(b);
    }
    
    /* (non-Javadoc)
	 * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#modifyInternalVariableOperator(br.ufmg.dees.insane.util.IMatrix, br.ufmg.dees.insane.util.IMatrix)
	 */
	public IMatrix modifyInternalVariableOperator(IMatrix e, IMatrix p) {
		double lf = p.getElement(3,0);
		int nNos = (e.getNumCol())/3;
		for(int i=0; i<nNos; i++){
            e.setElement(4,((3*i)+2),lf * (e.getElement(4,((3*i)+2))));
            e.setElement(5,((3*i)+2),lf * (e.getElement(5,((3*i)+2))));
		}
		return e;
	}

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getInternalVariableOperator(br.ufmg.dees.insane.util.IMatrix, br.ufmg.dees.insane.util.IVector, br.ufmg.dees.insane.util.IMatrix, br.ufmg.dees.insane.util.IMatrix)
     */
    public IMatrix getInternalVariableOperator(IMatrix d, IMatrix d2, IVector n, IMatrix c,
            IMatrix u) {
        // TODO Auto-generated method stub
        return null;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getDualInternalVariableOperator(br.ufmg.dees.insane.util.IMatrix)
     */
    public IMatrix getDualInternalVariableOperator(IMatrix e) {
        IMatrix d = new IMatrix(6,6);
        d.setZero();
        double G = e.getElement(3,3);
        double E = e.getElement(0,0);
        double ni = e.getElement(0,1);
        double alpha = e.getElement(3,1);
        d.setElement(0,0,(E/(1.0 - ni*ni)));
        d.setElement(0,3,(E*ni/(1.0 - ni*ni)));
        d.setElement(1,1,G + alpha);
        d.setElement(1,2,G - alpha);
        d.setElement(2,1,G - alpha);
        d.setElement(2,2,G + alpha);
        d.setElement(3,0,(E*ni/(1.0 - ni*ni)));
        d.setElement(3,3,(E/(1.0 - ni*ni)));       
        d.setElement(4,4,2.0*G);
        d.setElement(5,5,2.0*G);        
        return(d);
    }
    
	/* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getNumberOfInternalVariables()
     */
    public int getNumberOfInternalVariables() {
        return 6;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getNumberOfDualInternalVariables()
     */
    public int getNumberOfDualInternalVariables() {
        return 6;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getInternalVariablesVector(br.ufmg.dees.insane.util.IVector, br.ufmg.dees.insane.util.IMatrix)
     */
    public IVector getInternalVariablesVector(IVector a, IMatrix b) {
    	IVector strainVector = new IVector(7);
		strainVector.setElement(0, a.getElement(0)); 
		strainVector.setElement(1, a.getElement(1));
		strainVector.setElement(2, a.getElement(2));
		strainVector.setElement(3, a.getElement(3));
		strainVector.setElement(4, (-b.getElement(2,0)/(1 - b.getElement(2,0)))*(a.getElement(0)+a.getElement(3)));
		strainVector.setElement(5, a.getElement(4));
		strainVector.setElement(6, a.getElement(5));
		return strainVector;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getDualInternalVariablesVector(br.ufmg.dees.insane.util.IVector, br.ufmg.dees.insane.util.IMatrix)
     */
    public IVector getDualInternalVariablesVector(IVector a, IMatrix b) {
        return a;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getInternalVariablesTensor(br.ufmg.dees.insane.util.IVector, br.ufmg.dees.insane.util.IMatrix)
     */
    public IMatrix getInternalVariablesTensor(IVector a, IMatrix b) {
    	IMatrix Tensor = new IMatrix(6,6);
		Tensor.setZero();
        Tensor.setElement(0,0,a.getElement(0));
        Tensor.setElement(0,1,a.getElement(1));
        Tensor.setElement(1,0,a.getElement(2));
        Tensor.setElement(1,1,a.getElement(3));
        Tensor.setElement(2,2,(-b.getElement(2,0)/(1 - b.getElement(2,0)))*(a.getElement(0)+a.getElement(3)));
        Tensor.setElement(3,5,a.getElement(4));
        Tensor.setElement(4,5,a.getElement(5));        
        return Tensor;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getDualInternalVariablesTensor(br.ufmg.dees.insane.util.IVector, br.ufmg.dees.insane.util.IMatrix)
     */
    public IMatrix getDualInternalVariablesTensor(IVector a, IMatrix b) {
        return expandTensor(a);
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getInternalVariablesDirLabels()
     */
    public String[] getInternalVariablesLabels() {
        String[] Dlabels = {"GAMAxx", "GAMAxy", "GAMAyx", "GAMAyy", "KxzLf", "KyzLf"};
        return Dlabels;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getDualInternalVariablesDirLabels()
     */
    public String[] getDualInternalVariablesLabels() {
        String[] Dlabels = {"SIGMAxx", "SIGMAxy", "SIGMAyx", "SIGMAyy", "MIxz/Lf", "MIyz/Lf"};
        return Dlabels;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#expandVector(br.ufmg.dees.insane.util.IVector)
     */
    public IVector expandVector(IVector a) {
    	IVector Vector = new IVector(18);
        Vector.setElement(0,a.getElement(0));
        Vector.setElement(1,a.getElement(1));
        Vector.setElement(3,a.getElement(2));
        Vector.setElement(4,a.getElement(3));
        Vector.setElement(11,a.getElement(4));
        Vector.setElement(14,a.getElement(5));
        return Vector;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#expandTensor(br.ufmg.dees.insane.util.IVector)
     */
    public IMatrix expandTensor(IVector a) {
        IMatrix Tensor = new IMatrix(6,6);
		Tensor.setZero();
        Tensor.setElement(0,0,a.getElement(0));
        Tensor.setElement(0,1,a.getElement(1));
        Tensor.setElement(1,0,a.getElement(2));
        Tensor.setElement(1,1,a.getElement(3));        
        Tensor.setElement(3,5,a.getElement(4));
        Tensor.setElement(4,5,a.getElement(5));        
        return Tensor;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#reduceVector(br.ufmg.dees.insane.util.IVector)
     */
    public IVector reduceVector(IVector a) {
    	IVector Vector = new IVector(6);
        Vector.setElement(0,a.getElement(0));
        Vector.setElement(1,a.getElement(1));
        Vector.setElement(2,a.getElement(3));
        Vector.setElement(3,a.getElement(4));
        Vector.setElement(4,a.getElement(11));
        Vector.setElement(5,a.getElement(14));
        return Vector;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#reduceTensor(br.ufmg.dees.insane.util.IMatrix)
     */
    public IVector reduceTensor(IMatrix a) {
    	IVector Vector = new IVector(6);
        Vector.setElement(0,a.getElement(0,0));
        Vector.setElement(1,a.getElement(0,1));
        Vector.setElement(2,a.getElement(1,0));
        Vector.setElement(3,a.getElement(1,1));
        Vector.setElement(4,a.getElement(3,5));
        Vector.setElement(5,a.getElement(4,5));
        return Vector;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getLabel()
     */
    public String getLabel() {
        return "PolarPlaneStress";
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getJ2(br.ufmg.dees.insane.util.IVector)
     */
    public double getJ2(IVector s) {
    	double J2 = 0.0;
    	IMatrix P = this.getPMatrix();
        for(int i=0; i<this.getNumberOfInternalVariables(); i++)
            for(int j=0; j<this.getNumberOfInternalVariables(); j++)
               J2 += s.getElement(i) * P.getElement(i,j) * s.getElement(j);
        J2 *= 0.5;
        return(J2);
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getdJ2dSIG(br.ufmg.dees.insane.util.IVector)
     */
    public IVector getdJ2dSIG(IVector s) {
        // TODO Auto-generated method stub
        return null;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getJ3(br.ufmg.dees.insane.util.IVector)
     */
    public double getJ3(IVector s) {
        // TODO Auto-generated method stub
        return 0;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getdJ3dSIG(br.ufmg.dees.insane.util.IVector)
     */
    public IVector getdJ3dSIG(IVector s) {
        // TODO Auto-generated method stub
        return null;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getI1(br.ufmg.dees.insane.util.IVector)
     */
    public double getI1(IVector s) {
        // TODO Auto-generated method stub
        return 0;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getdI1dSIG(br.ufmg.dees.insane.util.IVector)
     */
    public IVector getdI1dSIG(IVector s) {
        // TODO Auto-generated method stub
        return null;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getI2(br.ufmg.dees.insane.util.IVector)
     */
    public double getI2(IVector s) {
        // TODO Auto-generated method stub
        return 0;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getdI2dSIG(br.ufmg.dees.insane.util.IVector)
     */
    public IVector getdI2dSIG(IVector s) {
        // TODO Auto-generated method stub
        return null;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getI3(br.ufmg.dees.insane.util.IVector)
     */
    public double getI3(IVector s) {
        // TODO Auto-generated method stub
        return 0;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.AnalysisModel#getdI3dSIG(br.ufmg.dees.insane.util.IVector)
     */
    public IVector getdI3dSIG(IVector s) {
        // TODO Auto-generated method stub
        return null;
    }
    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.analysisModel.PolarPlane#getPMatrix()
     */
    public IMatrix getPMatrix(){
        IMatrix P = new IMatrix(6,6);
		P.setZero();
        P.setElement(0,0, 2.0/3.0);
        P.setElement(3,3, 2.0/3.0);
        P.setElement(0,3, -1.0/3.0);        
        P.setElement(3,0, -1.0/3.0);        
        P.setElement(1,1, 1.0/2.0);
        P.setElement(1,2, 1.0/2.0);
        P.setElement(2,1, 1.0/2.0);
        P.setElement(2,2, 1.0/2.0);
        P.setElement(4,4, 1.0);
        P.setElement(5,5, 1.0);
        return P;
    }   
    
}
